<?php
namespace Beerus\Modules\SellGoods\Actions;

use Doraemon\model\SellGoods\SellGoodsInviteRecord;
use Encore\Admin\Actions\RowAction;
use Encore\Admin\Facades\Admin;
use Illuminate\Http\Request;

class AuditFail extends RowAction
{
	public $name = '拒绝';
	const TOAST_ALERT = '确定拒绝吗？';

	public function handle($id) {
		$result = SellGoodsInviteRecord::update([
			'data_status' => SellGoodsInviteRecord::STATUS_AUDIT_FAIL,
			'operated_at' => time(),
			'admin_id' => Admin::user()->id,
			'admin_name' => Admin::user()->username
		], [
			'id' => $id
		]);

		if ($result) {
			return $this->response()->success('操作成功(＾－＾)V')->refresh();
		}
        return $this->response()->success('操作失败,请稍后重试o(TωT)o');
	}

	public function retrieveModel(Request $request)
	{
		if (!$key = $request->get('_key')) {
			return false;
		}
		return $key;
	}

    public function dialog()
    {
        $this->confirm(self::TOAST_ALERT);
    }
}
